import { Component, OnInit } from '@angular/core';
import { Holidays } from '../../domain/holidays';
import { HolidayService } from '../../service/holiday.service';
import { Router } from '@angular/router';
import { postHolidays } from '../../domain/holidays'
// import { $ } from 'protractor';

@Component({
  selector: 'app-apply-for-leave',
  templateUrl: './apply-for-leave.component.html',
  styleUrls: ['./apply-for-leave.component.css']
})

export class ApplyForLeaveComponent implements OnInit {

  constructor(private holidayService: HolidayService, private _router: Router) { }

  submitHoliday(staffId: string, category: string, beginTime: string, endTime: string, reason: string) {
    // console.log(staffId);
    // console.log(category);
    beginTime = beginTime.trim();
    category = category.trim();
    staffId = staffId.trim();
    reason = reason.trim();
    endTime = endTime.trim();
    var holidayModel: postHolidays = new postHolidays(beginTime, endTime, category, reason, staffId, staffId);

    // this.holidayModel.fields.reason
    // var holidayJSON: string = "{staffId\":\"" + staffId + "\",\"beginTime\":\"" + beginTime + "\",\"endTime\":\"" + endTime + "\",\"reason\":\"" + reason + "\",\"category\":\"" + category + "\"}"
    this.holidayService.createHolidays(holidayModel)
      .then( () => {
        this._router.navigateByUrl('/staff-attendance/successful-interface');
      }
    )
  }
  ngOnInit() {
    
  }

}
